<!-- UserController.php-->
<?php 
	require 'Model/UserModel.php';
	require 'Controller.php';
	class UserController extends Controller{
		public $model;
		function __Construct(){
			parent::__Construct();
			$this->model = new UserModel();
		}
		function listusers(){
			$data = $this->model->getUserList();
			//转向用户列表页面
			//include 'user/userlist.php';
			$this->assign('departmentusers',$data);
			$this->display();
		}

		function userform(){
			//转向添加用户页面
			//include 'user/userform.php';
			$this->display();
		}

		function usersearch(){
			$name = $_POST['name'];
			$data = $this->model->getuserinfor($name);
			include 'View/user/search.php';
		}

		function useredit(){
			$id = $_GET['id'];
			$result = $this->model->getUserByID($id);
			//var_dump($result);
			include 'View/user/useredit.php';
		}

		function userupdate(){
			$id = $_GET['id'];
			$result = $this->model->Updateuser($id);
			if($result){
				echo '修改成功'.'<a href="Admin.php?c=user&m=listusers">如果没有跳转，请点这里跳转</a>';
				header("refresh:3;Admin.php?c=user&m=listusers = Admin.php?c=user&m=listusers"); 
			}else{
				echo '失败';
			}
		}

		function deluser(){
			$id = $_GET['id'];
			$result = $this->model->Deluser($id);
			if($result){
				echo '删除成功'.'<a href="Admin.php?c=user&m=listusers">如果没有跳转，请点这里跳转</a>';
				header("refresh:3;Admin.php?c=user&m=listusers = Admin.php?c=user&m=listusers"); 
			}else{
				echo '删除失败';
			}
		}

		function adduser(){
			//获取表单的数据
			//调用model中的addUser方法，添加到数据库中
			//var_dump($_POST);
			$data = $_POST;
			$result = $this->model->addUser($data);
			//如果成功，输出，转到列表页面
			if($result){
				echo '添加成功'.'<a href="../index.php">如果没有跳转，请点这里跳转</a>';
				header("refresh:3;../index.php = ../index.php"); 
			}else{
				echo '失败';
			}

		}
	}
 ?>